<?php
$form = $this->beginWidget('CActiveForm', array(
    'id'    => 'product-form',
    'focus' => array($model, 'title'),
    'errorMessageCssClass' => 'error',
    'htmlOptions'          => array(
        'enctype' => 'multipart/form-data',
        'class'   => 'form',
    ),
));

//hidden fields
echo $form->hiddenField($model, 'id');
echo $form->hiddenField($model, 'file1');
echo $form->hiddenField($model, 'file2');
?>

<table width="100%">
    <colgroup>
        <col width="220">
        <col width="340">
        <col>
    </colgroup>
    <tbody>
        <tr>
            <td>
                <div id="productPickfile_1" class="productPickfile_1">
                    <?php
                    $aSession = Yii::app()->user->getState($model->params['plupload_session']);
                    if ($aSession && isset($aSession['small'])) {
                        echo CHtml::image(Yii::app()->baseUrl
                            . Yii::app()->params['tempo_url']
                            . $aSession['small']['thumb_name']
                            . '?q=' . rand(1, 100)
                        );
                    }
                    ?>
                </div>
                <div id="productError_1" class="error">
                    <?php echo $form->error($model, 'file1'); ?>
                </div>
            </td>
            
            <td style="vertical-align: top;">
                <div id="productPickfile_2" class="productPickfile_2" title="Click here to upload">
                    <?php
                    if ($aSession && isset($aSession['normal'])) {
                        echo CHtml::image(Yii::app()->baseUrl
                            . Yii::app()->params['tempo_url']
                            . $aSession['normal']['thumb_name']
                            . '?q=' . rand(1, 100)
                        );
                    }
                    ?>
                </div>
                
                <div class="productCropControl">
                    <?php
                    $htmlOptions = array(
                        'id' => 'cropImage',
                        'class' => 'btn ui-state-default ui-corner-all btn-cancel',
                    );
                    if ( $model->getIsNewRecord() && (! isset($aSession['normal'])) ) {
                        $htmlOptions['class'] = 'btn ui-state-hover ui-corner-all btn-cancel';
                    }
                    echo CHtml::link('<span class="ui-icon ui-icon-image"></span>CROP',
                        'javascript:void(0)', $htmlOptions
                    );
                    ?>
                </div>
                <div class="clear"></div>
                
                <div id="productError_2" class="error" style="margin-left: 20px;">
                    <?php echo $form->error($model, 'file2'); ?>
                </div>
            </td>
            
            <td style="vertical-align: top;">
                <fieldset>
                    <ul>
                        <li>
                            <?php
                                $attr = 'type_id';
                                echo $form->label($model, $attr, array(
                                    'required' => true,
                                    'class'    => 'desc',
                                ));
                            ?>
                            <div><?php
                                $data = DNewsletterType::model()->getMenu(true);

                                $this->widget('ArrayToDropDownList', array(
                                    'model'         => $model,
                                    'attribute'     => $attr,
                                    'data'          => $data,
                                    'parentId'      => 3, //product
                                    'disableParent' => true,
                                    'selected'      => $model->getAttribute('type_id'),
                                    'htmlOptions'   => array(
                                        'id'    => 'type_id',
                                        'class' => 'select',
                                    ),
                                ));
                                echo $form->error($model, $attr);
                            ?></div>
                        </li>
                        
                        <li>
                            <?php
                                $attr = 'project';
                                echo $form->label($model, $attr, array(
                                    'required' => true,
                                    'class' => 'desc',
                                ));
                            ?>
                            <div><?php
                                echo $form->textField($model, $attr, array(
                                    'class' => 'text full'
                                ));
                                echo $form->error($model, $attr);
                            ?></div>
                        </li>

                        <li>
                            <?php
                                $attr = 'career';
                                echo $form->label($model, $attr, array(
                                    'class'    => 'desc',
                                ));
                            ?>
                            <div><?php
                                echo $form->textField($model, $attr, array(
                                    'class' => 'text full'
                                ));
                                echo $form->error($model, $attr);
                            ?></div>
                        </li>
                        
                        <li>
                            <?php
                                $attr = 'country';
                                echo $form->label($model, $attr, array(
                                    'class'    => 'desc',
                                ));
                            ?>
                            <div><?php
                                echo $form->textField($model, $attr, array(
                                    'class' => 'text full'
                                ));
                                echo $form->error($model, $attr);
                            ?></div>
                        </li>
                        
                        <li>
                            <?php
                                $attr = 'link';
                                echo $form->label($model, $attr, array(
                                    'class'    => 'desc',
                                    'style'    => 'display: inline;'
                                ));
                                echo '&nbsp;&nbsp;';
                                echo CHtml::link('(?)', 'javascript:void(0)', array(
                                    'id'    => 'assign-link',
                                    'class' => 'link_strong',
                                    'title' => 'helper',
                                    'style' => 'display: inline;'
                                ));
                            ?>
                            <div><?php
                                echo $form->textField($model, $attr, array(
                                    'class' => 'text full'
                                ));
                                echo $form->error($model, $attr);
                            ?></div>
                        </li>
                        
                        <li>
                            <?php
                            echo CHtml::label(
                                $model->getAttributeLabel('status'),
                                'status',
                                array('class' => 'desc'));
                            ?>
                            <div>
                                <table>
                                    <tr>
                                        <td><?php
                                        $attr = 'activated_flag';
                                        echo $form->checkBox($model, $attr, array(
                                            'class' => 'checkbox',
                                        ));
                                        echo CHtml::label($model->getAttributeLabel($attr),
                                            'DProduct2_activated_flag',
                                            array('class' => 'choice', 'style'=>'margin-right:25px;'));
                                        ?></td>
                                    </tr>
                                </table>
                            </div>
                        </li>

                        <!-- buttons -->
                        <li style="text-align: center;">
                        <?php
                        echo CHtml::submitButton(($model->getScenario() == 'insert') ? 'CREATE' : 'SAVE', array(
                            'name'  => 'submit',
                            'class' => 'ui-state-default ui-corner-all ui-button'
                        ));
                        echo CHtml::button('RESET', array(
                            'type'  => 'button',
                            'id'    => 'btn-reset',
                            'class' => 'ui-state-default ui-corner-all ui-button',
                            'style' => 'margin:0 10px;',
                            'ref' => ($model->getScenario() == 'insert') ? $this->createUrl('create') 
                                : $this->createUrl('update', array('id'=>$model->id)),
                        ));
                        echo CHtml::button('CANCEL', array(
                            'id'    => 'btn-cancel',
                            'class' => 'ui-state-default ui-corner-all ui-button btn-cancel'
                        ));
                        ?>
                        </li>
                        <!-- //buttons -->
                    </ul>
                </fieldset>
            </td>
        </tr>
    </tbody>
</table>

<?php $this->endWidget(); ?>

<div id="cropImageDialog" style="display:none;"></div>

<!-- Dialog -->
<div id="dialogLinks" title="Quick links" style="display:none;"></div>
<!-- End of Dialog -->